<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}
// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
	{				
				$shiptitle = mysql_real_escape_string($_REQUEST['shiptitle']);
				$shipdesc = mysql_real_escape_string($_REQUEST['shipdesc']);
				$sltstatus = mysql_real_escape_string($_REQUEST['sltstatus']);
				$shipcost = mysql_real_escape_string($_REQUEST['shipcost']);
				$slttax = mysql_real_escape_string($_REQUEST['slttax']);
				$slttclass = mysql_real_escape_string($_REQUEST['txclass']);		
				
				$insert="INSERT INTO `tblshippingmaster`
				(`vartitle` , `vardesc` , `intstatus`, `decshipcost`, `inttax`, `inttaxclass`) 
				VALUES ('$shiptitle', '$shipdesc', '$sltstatus', '$shipcost', '$slttax', '$slttclass')";
				
				$sql=$obj_db->insert($insert);
				
				
				
				header("location:shipping.php?msg=add");
				die();
	}	
		

// UPDATE the record
$shiptitle1 = "";
$shipdesc1 = "";
$sltstatus1 = "";
$shipcost1 = "";
$slttax1 = "";
$txclass = "";

$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql = "select * from tblshippingmaster where intid ='$id'";
		$result = $obj_db->select($sql);
		
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		
		if($result)
		{
			foreach($result as $row)
			{
				$shiptitle1 = $row['vartitle'];	   
		   		$shipdesc1 = $row['vardesc'];
				$sltstatus1 = $row['intstatus'];
				$shipcost1 = $row['decshipcost'];	   
		   		$slttax1 = $row['inttax'];
				$txclass = $row['inttaxclass'];
				
				
				$action=2;
			}
		}
		
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
				$shiptitle = mysql_real_escape_string($_REQUEST['shiptitle']);
				$shipdesc = mysql_real_escape_string($_REQUEST['shipdesc']);
				$sltstatus = mysql_real_escape_string($_REQUEST['sltstatus']);
				$shipcost = mysql_real_escape_string($_REQUEST['shipcost']);
				$slttax = mysql_real_escape_string($_REQUEST['slttax']);
				$slttclass = mysql_real_escape_string($_REQUEST['txclass']);
			
			$sql_upd ="UPDATE tblshippingmaster SET  
						`vartitle` = '$shiptitle',
						`vardesc` = '$shipdesc',						 
						`intstatus` = '$sltstatus',
						`decshipcost` = '$shipcost',
						`inttax` = '$slttax',						 
						`inttaxclass` = '$slttclass'
						where intid ='$id'";
			$result = $obj_db->edit($sql_upd);
			$action=1;
			
			header("location:shipping.php?msg=edit");
			die();
		}
	}

}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql= "DELETE FROM `tblshippingmaster` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		
		header("location:shipping.php?msg=del");
		die();
	}
}

// change status Approve or Not Approve
if(isset($_REQUEST['status']) && trim($_REQUEST['status']) == 0)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{
		$id=mysql_real_escape_string($_REQUEST['intid']);
		$sql="update tblshippingmaster set intstatus = 1 where intid = $id";
		
		$update = $obj_db->sql_query($sql);
		
		header("location:shipping.php");
		die();
	}
}
if(isset($_REQUEST['status']) && trim($_REQUEST['status']) == 1)
{
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{
		$id=mysql_real_escape_string($_REQUEST['intid']);
		$sql="update tblshippingmaster set intstatus = 0 where intid = $id";
		
		$update = $obj_db->sql_query($sql);
		
		header("location:shipping.php");
		die();
	}
}



?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/shipping.js"></script>
<script language="javascript" src="js/maincommon.js"></script>

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="95%"><?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addshipping' || trim($_REQUEST['script'])=='editshipping')
	{
	?>
		<form action="" method="post" enctype="multipart/form-data" name="shipping">		
      <table width="60%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addshipping'){echo "Add New Shipping...";}
	if($_REQUEST['script']=='editshipping'){echo "Edit Shipping...";}?>
          </strong></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">(* All fields are Required)</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td width="2%">&nbsp;</td>
          <td width="30%" align="right" class="sltimg">*Shipping Title </td>
          <td width="3%">:</td>
          <td width="56%" align="left"><label>
            <input name="shiptitle" type="text" id="shiptitle" value="<?php echo stripslashes($shiptitle1);?>" />
          </label></td>
          <td width="9%">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Description</td>
          <td>:</td>
          <td align="left"><input name="shipdesc" type="text" id="shipdesc" value="<?php echo stripslashes($shipdesc1);?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Status</td>
          <td>:</td>
          <td align="left"><select name="sltstatus" id="sltstatus">
            <option value="2" <?php if($sltstatus1==2) {?> selected="selected"<?php } ?> >Status</option>
            <option value="1" <?php if($sltstatus1==1) {?> selected="selected"<?php } ?>>Enable</option>
            <option value="0" <?php if($sltstatus1==0) {?> selected="selected"<?php } ?>>Disable</option>
          </select>
          </td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Shipping Cost </td>
          <td>:</td>
          <td align="left"><input name="shipcost" type="text" id="shipcost" value="<?php echo stripslashes($shipcost1);?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Tax</td>
          <td>:</td>
          <td align="left"><select name="slttax" id="slttax">
            <option value="2">Select Tax</option>
            <option value="1" <?php if($slttax1==1){ ?> selected="selected" <?php } ?>>Yes  </option>
            <option value="0" <?php if($slttax1==0){ ?> selected="selected" <?php } ?>>No</option>
                              </select></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Tax Class </td>
          <td>:</td>
          <td align="left"><select name="txclass" id="txclass">
<option value="0">None</option>
<?php
$sql="select * from tbltaxclass";
$resman = $obj_db->select($sql);

if(count($resman)>0)
{
	for($m=0;$m<count($resman);$m++)
	{


?>
<option value="<?php echo $resman[$m]['intid'];?>"<?php if($resman[$m]['intid'] == $txclass){echo "selected";}else{echo "";} ?>><?php echo stripslashes($resman[$m]['vartaxtitle']);?></option>
<?php
	}
}
?>
</select></td>
          <td>&nbsp;</td>
        </tr>
        

        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table></form>
    <?php
	}
}
else
{
?>
<br /><br />
		<table width="75%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
          <tr class="bg1">
            <td colspan="7" align="left"><strong>Shipping Master...</strong></td>
            <td align="center"><a href="shipping.php?script=addshipping" class="aa">[NEW]</a></td>
          </tr>
          <tr>
             <?php 
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="8" align="left">
			  
			  Row per Page:
                <select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}else{echo "";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}else{echo "";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}else{echo "";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}else{echo "";}?>>15 Per Page</option>
                </select>
				
			   </td></form>
          </tr>
          <tr class="tblbg3">
            <td align="center"><strong>Title </strong></td>
            <td align="center" class="tblbg3"><strong>Description</strong></td>
            <td align="center" class="tblbg3"><strong>Status</strong></td>
			<td align="center" class="tblbg3"><strong>Cost</strong></td>
			<td align="center" class="tblbg3"><strong>Tax</strong></td>
			<td align="center" class="tblbg3"><strong>Tax Class</strong></td>
            <td align="center" class="tblbg3"><strong>Edit</strong></td>
            <td align="center" class="ab"><strong>Delete</strong></td>
          </tr>
          <?php
	  
	  
	  
	  /**************************************
		PAGING CODE START
		**************************************/
		if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0)
			{
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			}else{$rowperpage=$rows=10000;}

		$tablename="tblshippingmaster";
		$per_page_keywords= "";
		$per_page_sorts="";
		include("system/paging.inc.php");

		/**************************************
		PAGING CODE ENDING
		**************************************/
		?>
          <?php
   		$sql="select * from tblshippingmaster Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			//$imagepath = "../images/manuf/";
			//$limit=$result[$i]['varimagepath'];
			//$imagename = $imagepath.$limit;
			?>
          <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onMouseOut="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
            <td align="center"><?php echo stripslashes($result[$i]['vartitle']);?></td>
			  
            <td align="center"><?php echo stripslashes($result[$i]['vardesc']);?></td>
            <td><table border="0" cellspacing="0" cellpadding="0" align="center">
				  <tr><?php 
					if($result[$i]['intstatus']==0)
					{
						echo "<td><a class='aa' Title='Click here to Disable Shipping' href='shipping.php?status=0&intid=$id'>Disable</a></td>";	
					} 
					if($result[$i]['intstatus']==1)
					{
						echo "<td><a class='aa' Title='Click here to Enable Shipping' href='shipping.php?status=1&intid=$id'>Enable</a></td>";	
					} 
				  ?> </tr>
				</table></td>
			<td align="center"><?php echo stripslashes($result[$i]['decshipcost']);?></td>
			<td align="center">
<?php 		
		if($result[$i]['inttax']=='0')
		{
			echo "No";
		}
		if($result[$i]['inttax']=='1')
		{
			echo "Yes";
		}
		if($result[$i]['inttax']=='2')
		{
			echo "Not Selected";
		}
?>			</td>
			<td align="center">
<?php 		
		$sqli="SELECT * FROM `tbltaxclass` WHERE `intid`=".$result[$i]['inttaxclass'];
		$resname = $obj_db->select($sqli);
		if(count($resname)>0)
		{
			for($pn=0;$pn<count($resname);$pn++)
			{
				echo $resname[$pn]['vartaxtitle'];
			}
		}
?>			</td>
            <td align="center"><a class="link" Title="Click here to Edit" href="shipping.php?script=editshipping&amp;a=2&amp;intid=<?php echo $result[$i]['intid']; ?>"><img src="images/edit.bmp" border="0"/></a></td>
            <td align="center"><a Title="Click here to Delete" href="shipping.php?a=3&amp;intid=<?php echo $result[$i]['intid']; ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
          </tr>
          <?php }}?>
          <tr>
            <td colspan="8" align="center"><?php
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?></td>
          </tr>
        </table>
		<?php }?>
 </td>
    <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>
</body>
</html>

